<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<div id="div">
			<img src="img/APPtubiao.png" />
			<!--<img src=""/>-->
			<!--<img src=""/>-->
		</div>
		<button id="btn">上传</button>
		<script src="js/jquery-1.11.0.js" ype="text/javascript" charset="utf-8"></script>
		<script src="js/str_ys/pako.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/str_ys/jquery-qrcode.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/back_end.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function getBase64(img) { //传入图片路径，返回base64
				function getBase64Image(img, width, height) { //width、height调用时传入具体像素值，控制大小 ,不传则默认图像大小
					var canvas = document.createElement("canvas");
					canvas.width = width ? width : img.width;
					canvas.height = height ? height : img.height;

					var ctx = canvas.getContext("2d");
					ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
					var dataURL = canvas.toDataURL();
					return dataURL;
				}
				var image = new Image();
				image.src = img;
				var deferred = $.Deferred();
				if(img) {
					image.onload = function() {
						deferred.resolve(getBase64Image(image)); //将base64传给done上传处理
					}
					return deferred.promise(); //问题要让onload完成后再return sessionStorage['imgTest']
				}
			}

			$("#btn").click(function() {
				var imgsrc = $("#div img").attr("src");
				getBase64(imgsrc).then(function(base64) {
					console.log(base64);
					var binaryString = pako.deflate(JSON.stringify(str), { to: 'string' });//字符串压缩处理
					//					base64 = base64.substr(0, 450000);
					//					console.log(base64);
					//					base64 = base64.substring(22);
//					var sendURLModel = [];
//					sendURLModel.push(base64);
////					var sendJson = {a:base64};
//					console.log(sendJson);
//					var lengthNumStr = base64.length.toString(); //总长度数的字符串
//					var yushu = lengthNumStr.substr(lengthNumStr.length - 5, lengthNumStr.length); //字符串长度 整除1000的余数
//					var cycleTimes = parseInt(base64.length / 100000);
//										console.log(cycleTimes);
//					for(var i = 0; i < cycleTimes.length; i++) {
//						sendURLModel.push(base64.substring(0, 100000)); //base64字符串隔1000位一截取
//						base64 = base64.substr(100000); //截取过后的base64字符串 循环截取
//						if(i == 1){
//							console.log(sendURLModel);
//							break;
//						}
//					}
					//					var URLlength = base64.length; 
					//					var URLpart = 5000; // 一段取几个字符
					//					var URLPartLength = URLlength / URLpart;
					//					url分成几段

					//					for(var j = 0; j < URLPartLength; j++) {
					//						sendURLModel.push(base64.substring(0, URLpart));
					//						base64 = base64.substr(URLpart);
					//					}
//					sendPic(base64);
//					sendPic(sendJson);

				}, function(err) {
					console.log("图片转换失败");
				});
			});
			
//			function ceshiArr(){
//				alert(sendURLModel);
//			}
			function sendPic(xx) {
				//				console.log(sendURLModel);
				//				for(var i = 0; i < URLPartLength; i++) {
				$.ajax({
					type: "post",
					url: Url,
					contentType: "application/x-www-form-urlencoded",
					data: {
						"type": "save_travel_notes",
						"SCENIC": "长白山",
						"CREATEPERSON": "13601014569",
						"NOTES": "游记文字内容",
						"TRAVELSTIME": "2017-10-25 09:00:00",
						"PICTURE1": xx,
						"SCORE": "10"

					},
					async: false,
					cache: false,
					dataType: "jsonp", //数据类型为jsonp
					jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
					jsonpCallback: "jsonpCallback1",
					success: function(data) {
						console.log(data);
					},
					error: function(data) {
						//							$.alert("连接超时，请检查网络设置", "提示");
						console.log(error);
					}
				});
				//				}
			}

			//			var sendURLModel = [];
			//			var URLLength = url.length; // 470000
			//			var URLpart = 5000; // 一段取几个字符
			//			var URLPartLength = URLLength / URLpart; // url分成几段
			//
			//			// 组装 传递数组
			//			for(let j = 0; j < URLPartLength; j++) {
			//				sendURLModel.push(url.substring(0, URLpart));
			//				url = url.substr(URLpart);
			//			}
			//
			//			// 发送请求
			//			for(let i = 0; i < URLPartLength; i++) {
			//				$.ajax({
			//					type: 'post',
			//					url: '/test/check',
			//					data: sendURLModel[i],
			//					cache: false,
			//					async: false,
			//					dataType: 'json',
			//					success: function(data) {
			//
			//					},
			//					error: function(error) {
			//						alert('请求失败！' + error);
			//					}
			//				});
			//			}
		</script>
	</body>

</html>